<template>
    <div class="app">
        <Show 
        @edit="edit"
        @changeColor="changeColor"
        :appInfo="appInfo"></Show>
        <Dialog
            ref="dialog"
            :appInfo="appInfo"
            @confirmChange="confirmChange"
        ></Dialog>
    </div>
</template>

<script>
import axios from 'axios'
import Show from './Show'
import Dialog from './Dialog'
import { setTimeout } from 'timers';
export default {
    name: 'App',
    components: {
      Show,
      Dialog
    },
    created() {
        this.loadAppInfo();
        
    },
    data() {
        return {
            appInfo: {}
        }
    },
    methods: {
        loadAppInfo () {
            this.$store.commit('showLoading');
            axios.get('/index/App/getAppInfo')
            .then((datas) => {
                var data = datas.data;
              
                if (data.status === 0) {
                    this.appInfo = data.data;
                }
                else {
                    this.$message.error('加载失败，网络挂了！');
                }
                //隐藏加载
                this.$store.commit('hiddenLoading');
            }, (err) => {
                this.$message.error('加载失败，网络挂了！');
            });
        },
        edit () {
            this.$refs.dialog.show();
        },
        changeColor () {
            this.confirmChange();
        },
        confirmChange () {
            var appInfo = this.appInfo;
            this.$store.commit('showLoading');
            axios.get('/index/App/updateAppInfo', {
                params: {
                appName: appInfo.appName,
                subjectColor: appInfo.subjectColor,
                appModel: appInfo.appModel,
                askRule: appInfo.askRule,
                chargeFee: appInfo.chargeFee || 0,
                appId: appInfo.appId,
                appSecret: appInfo.appSecret,
                qiniuAccessKey: appInfo.qiniuAccessKey,
                qiniuSecretKey: appInfo.qiniuSecretKey,
                qiniuBucket: appInfo.qiniuBucket,
                qiniuDomain: appInfo.qiniuDomain
            }
            }).then((datas) => {
                console.log(datas)
                var data = datas.data;
                if (data.status === 0) {
                    this.$message({
                        message: '更新成功',
                        type: 'success'
                    });
                }
                else {
                    this.$message.error('更新错误，网络挂了！');
                }
                this.loadAppInfo();
                
            }, (err) => {
                this.$message.error('更新错误，网络挂了！');
                this.loadAppInfo();
            });
            
        }
    }
}
</script>

<style lang="stylus" scoped>
    .app
        width 100%
        height 100%
        
        
        

</style>


